﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using System.Data;
using BLL;
namespace Web.admin.InnerManage
{
    public partial class AddInnerSummary : System.Web.UI.Page
    {
        ContestService contestService = new ContestService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string operation = Request["OPERATION"];
                string compId = Request["id"];
                string test = Request["MOD"];
                //if (compId == null)
                //    return;

                if (operation == "Modify")
                {
                    ModifyInner(compId, test);
                }
                else if (operation == "Delete")
                {
                    DeleteInner(compId, test);
                }
                Par_contest.DataSource = contestService.getInnerContests();
                Par_contest.DataTextField = "CON_NAME";
                Par_contest.DataValueField = "CON_ID";
                Par_contest.DataBind();
                if (Session["selectValue"] != null && Session["selectValue"].ToString() != "")
                    Par_contest.SelectedValue = Session["selectValue"].ToString();
            }
            
        }
        protected void ModifyInner(string conId, string mod)
        {
            BoContests con = contestService.getContest(conId);

            Par_contest.DataSource = contestService.getAllContests();
            Par_contest.DataTextField = "CON_NAME";
            Par_contest.DataValueField = "CON_ID";
            Par_contest.DataBind();
            Par_contest.SelectedValue = con.CON_ID;

            if (mod == "F1")
            {
                SummaryList.SelectedValue = "2";

            }
            else if (mod == "F2")
            {
                SummaryList.SelectedValue = "1";

            }
            else if (mod == "F3")
            {
                SummaryList.SelectedValue = "0";

            }

        }
        protected void DeleteInner(string conId, string mod)
        {
            BoContests con = contestService.getContest(conId);
            if (mod == "F1")
            {
                con.CON_EXPERIENCE = "";
            }
            else if (mod == "F2")
            {
                con.CON_IMPROVE = "";
            }
            else if (mod == "F3")
            {
                con.CON_SUMMARY = "";
            }
            contestService.UpdateContest(con);
            Response.Redirect("InnerSummary.aspx");
        }
        /// <summary>
        /// 保存按钮点击
        /// </summary>
        /// <param name="sender">对象</param>
        /// <param name="e">事件</param>
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            BoContests con = contestService.getContest(Par_contest.SelectedValue);

            if (SummaryList.SelectedValue == "0")
            {
                con.CON_SUMMARY = KindEditor.Text.ToString();
            }
            else if (SummaryList.SelectedValue == "1")
            {
                con.CON_IMPROVE = KindEditor.Text.ToString();
            }
            else if (SummaryList.SelectedValue == "2")
            {
                con.CON_EXPERIENCE = KindEditor.Text.ToString();
            }
            con.CON_ISSHOW = 4;
            contestService.UpdateContest(con);
            Response.Redirect("InnerSummary.aspx");
            Response.Write("<script>alert('修改成功')</script>");
         

        }
        /// <summary>
        /// 对列表的填充
        /// </summary>
        /// <param name="id">数据的id</param>
        protected void List_Bind(string id)
        {
            //BoNewsContent newsModel = newscontent.GetNewsSingle(id);
            //if (newsModel != null)
            //{
            //    DDLClass.SelectedValue = newsModel.NewsClassId;
            //    TitleTxt.Value = newsModel.NewsTitle;
            //    FromTxt.Value = newsModel.NewsAuthor;
            //    UrlTxt.Value = newsModel.NewsImgUrl;
            //    KindEditor.Text = newsModel.NewsArticle;
            //    AttributeDDL.SelectedValue = newsModel.NewsIsShow.ToString();
            //}
        }

        /// <summary>
        /// 对DropDownList的绑定
        /// </summary>
        /// <param name="firstStr">第一行显示的数据</param>
        /// <param name="ddl">DropDownList控件</param>
        protected void DDLBind(string firstStr, DropDownList ddl)
        {
            //if (!string.IsNullOrEmpty(firstStr))
            //{
            //    ddl.Items.Add(new ListItem(firstStr, ""));
            //}
            //DataTable table = newsClass.GetNewsClass();
            //foreach (DataRow dr in table.Rows)
            //{
            //    ddl.Items.Add(new ListItem(dr["NCTitle"].ToString(), dr["NCId"].ToString()));
            //}
        }

        protected void Par_contest_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}